<?php
class Administrator_ComponentController extends Nguyen_Controller_Action {
	public function init() {
		$this->loadTemplate ( 'administrator' );
		$this->AdminOnly();
	}
	public function indexAction() {
		$model = new Administrator_Model_Component ();
		$task = $this->_request->getParam ( 'task', 'list' );
		$id = $this->_request->getParam ( 'id' );
		$this->view->task = $task;
		$this->view->id = $id;
		if ($this->_request->isPost ()) {
			if ($this->_request->getParam ( 'btadd' )) {
				$this->_redirect ( '/administrator/component?task=new' );
			}
			if ($this->_request->getParam ( 'btsave' )) {
				$name = $this->_request->getParam ( 'name', '' );
				$display = $this->_request->getParam ( 'display', '' );
				if ($task == 'new') {
					$model->InsertComponent ( $name, $display );
				}
				if ($task == 'edit') {
					$model->UpdateComponent ( $id, $name, $display );
				}
				$this->_redirect ( '/administrator/component' );
			}
			if ($this->_request->getParam ( 'btedit' )) {
				foreach ( $model->GetAllComponent () as $value ) {
					if ($this->_request->getParam ( $value ['id'] ))
						$this->_redirect ( '/administrator/component?task=edit&id=' . $value ['id'] );
				}
			}
			if ($this->_request->getParam ( 'btdelete' )) {
				foreach ( $model->GetAllComponent () as $value ) {
					if ($this->_request->getParam ( $value ['id'] ))
						$model->DelComponent ( $value ['id'] );
				}
				$this->_redirect ( '/administrator/component' );
			}
			if ($this->_request->getParam ( 'btback' )) {
				$this->_redirect ( '/administrator/component' );
			}
			if ($this->_request->getParam ( 'btoption' )) {
				$this->_redirect ( '/administrator' );
			}
		}
		$this->view->headTitle ( 'Control Panel | Thông tin thể loại', true );
	}
	
	public function addonAction() {
		$model = new Administrator_Model_Component ();
		$task = $this->_request->getParam ( 'task', 'list' );
		$id = $this->_request->getParam ( 'id' );
		$this->view->task = $task;
		$this->view->id = $id;
		if ($this->_request->isPost ()) {
			if ($this->_request->getParam ( 'btadd' )) {
				$this->_redirect ( '/administrator/component/addon?task=new' );
			}
			if ($this->_request->getParam ( 'btsave' )) {
				$controller = $this->_request->getParam ( 'component', '' );
				$name = $this->_request->getParam ( 'name', '' );
				$display = $this->_request->getParam ( 'display', '' );
				if ($task == 'new') {
					$model->InsertAction ( $name, $display, $controller );
				}
				if ($task == 'edit') {
					$model->UpdateAction ( $id, $name, $display, $controller );
				}
				$this->_redirect ( '/administrator/component/addon' );
			}
			if ($this->_request->getParam ( 'btedit' )) {
				foreach ( $model->GetAllAction () as $value ) {
					if ($this->_request->getParam ( $value ['id'] ))
						$this->_redirect ( '/administrator/component/addon?task=edit&id=' . $value ['id'] );
				}
			}
			if ($this->_request->getParam ( 'btdelete' )) {
				foreach ( $model->GetAllAction () as $value ) {
					if ($this->_request->getParam ( $value ['id'] ))
						$model->DelAction ( $value ['id'] );
				}
				$this->_redirect ( '/administrator/component/addon' );
			}
			if ($this->_request->getParam ( 'btback' )) {
				$this->_redirect ( '/administrator/component/addon' );
			}
			if ($this->_request->getParam ( 'btoption' )) {
				$this->_redirect ( '/administrator' );
			}
		}
		$this->view->headTitle ( 'Control Panel | Thông tin chức năng', true );
	}
	
	
	
	
	
	
	public function viewAction() {
		$model = new Administrator_Model_Component ();
		$task = $this->_request->getParam ( 'task', 'list' );
		$id = $this->_request->getParam ( 'id' );
		$this->view->task = $task;
		$this->view->id = $id;
		if ($this->_request->isPost ()) {
			if ($this->_request->getParam ( 'btadd' )) {
				$this->_redirect ( '/administrator/component/view?task=new' );
			}
			if ($this->_request->getParam ( 'btsave' )) {
				$action = $this->_request->getParam ( 'addon', '' );
				$name = $this->_request->getParam ( 'name', '' );
				$display = $this->_request->getParam ( 'display', '' );
				if ($task == 'new') {
					$model->InsertView ( $name, $display, $action );
				}
				if ($task == 'edit') {
					$model->UpdateView( $id, $name, $display, $action );
				}
				$this->_redirect ( '/administrator/component/view' );
			}
			if ($this->_request->getParam ( 'btedit' )) {
				foreach ( $model->GetAllView () as $value ) {
					if ($this->_request->getParam ( $value ['id'] ))
						$this->_redirect ( '/administrator/component/view?task=edit&id=' . $value ['id'] );
				}
			}
			if ($this->_request->getParam ( 'btdelete' )) {
				foreach ( $model->GetAllView () as $value ) {
					if ($this->_request->getParam ( $value ['id'] ))
						$model->DelView ( $value ['id'] );
				}
				$this->_redirect ( '/administrator/component/view' );
			}
			if ($this->_request->getParam ( 'btback' )) {
				$this->_redirect ( '/administrator/component/view' );
			}
			if ($this->_request->getParam ( 'btoption' )) {
				$this->_redirect ( '/administrator' );
			}
		}
		$this->view->headTitle ( 'Control Panel | Thông tin View', true );
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public function siteinfoAction() {
		$this->AdminOnly ();
		$model = new Administrator_Model_System ();
		if ($this->_request->isPost ()) {
			if ($this->_request->getParam ( 'btsave' )) {
				$sitename = $this->_request->getParam ( 'sitename', '' );
				$meta = $this->_request->getParam ( 'meta', '' );
				$description = $this->_request->getParam ( 'description', '' );
				$email = $this->_request->getParam ( 'email', '' );
				$website = $this->_request->getParam ( 'website', '' );
				$fax = $this->_request->getParam ( 'fax', '' );
				$phone = $this->_request->getParam ( 'phone', '' );
				$mobile = $this->_request->getParam ( 'mobile', '' );
				$address = $this->_request->getParam ( 'address', '' );
				$status = $this->_request->getParam ( 'multilang', '' );
				$model->UpdateSiteInfo ( $sitename, $meta, $description, $email, $website, $fax, $phone, $mobile, $address, $status );
				$this->_redirect ( '/administrator/index/siteinfo' );
			}
			if ($this->_request->getParam ( 'btback' )) {
				$this->_redirect ( '/administrator' );
			}
		}
		$this->view->headTitle ( 'Control Panel | Thông tin website', true );
	}
	public function noaccessAction() {
	
	}
}